// MayBe函子

class MayBe {
    static of(value) {
        return new MayBe(value);
    }
    constructor(value) {
        this._value = value;
    }
    // 如果对空值变形的话直接返回 值为 null 的函子
    map(fn) {
        return this.isNothing() ? MayBe.of(null) : MayBe.of(fn(this._value));
    }
    isNothing() {
        return this._value === null || this._value === undefined;
    }
}

let r = MayBe.of(null).map((x) => x.toUpperCase());
// => MayBe { _value: null }

// let r = MayBe.of(5)
//     .map((x) => x * 2)
//     .map((x) => null);
//     .map((x) => x + 1);
// => MayBe { _value: null }
console.log(r);
